﻿using MyBasicLib.Serialization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace MyBasicLib.Test
{


    /// <summary>
    ///This is a test class for ISerializerTest and is intended
    ///to contain all ISerializerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ISerializerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DeSerializer
        ///</summary>
        public void SerializerTestHelper<T>(ISerializer<T> target, T expected, Func<T, T, bool> func)
        {
            //ISerializer<T> target = CreateISerializer<T>(); // TODO: Initialize to an appropriate value
            byte[] data = null; // TODO: Initialize to an appropriate value
            // T expected = default(T); // TODO: Initialize to an appropriate value
            T actual;
            data = target.Serializer(expected);
            actual = target.DeSerializer(data);
            Assert.IsTrue(func(expected, actual));

        }
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentException))]
        public void XmlSerializerTest_must_have_Serializable()
        {
            var x = new XmlSerializer<GenericParameterHelper>();
            SerializerTestHelper<GenericParameterHelper>(x, new GenericParameterHelper() { Data = 5 }, (p, q) => p.Data == q.Data);
       }
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentException))]
        public void BinarySerializerTest_must_have_Serializable()
        {
            var x = new BinarySerializer<GenericParameterHelper>();
            SerializerTestHelper<GenericParameterHelper>(x, new GenericParameterHelper() { Data = 5 }, (p, q) => p.Data == q.Data);
        }

        [TestMethod()]
        public void XmlSerializerTest()
        {
            var x = new XmlSerializer<RUC.Core.Entities.App>();
            SerializerTestHelper<RUC.Core.Entities.App>(x, new RUC.Core.Entities.App() { Id = "6" }, (p, q) => p.Id == q.Id);
        }
        [TestMethod()]
        public void BinarySerializerTest()
        {
            var x = new BinarySerializer<RUC.Core.Entities.App>();
            SerializerTestHelper<RUC.Core.Entities.App>(x, new RUC.Core.Entities.App() { Id = "6" }, (p, q) => p.Id == q.Id);
        }

    }
}
